package com.bj58.ecdata.monitor.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bj58.ecdata.webframework.BaseController;

/**
 * 数据修复工具类，主要用于修复小时数据，从mysql导入redis
 * @author lichao
 */
@Controller
@RequestMapping("/fix")
public class DataFixController extends BaseController {
	Logger log = LoggerFactory.getLogger(DataFixController.class);

//	@Autowired
//	private ClickDao click;
//	@Autowired
//	private DisplayDao display;
//	@Autowired
//	private TrackDao track;
//	@Autowired(required=false)
//	private TrackDao_TMP track_tmp;

	@RequestMapping("/click")
	@ResponseBody
	public String click(@RequestParam String time, @RequestParam(required = false, defaultValue = "15") int count) {
		return "";
	}

	@RequestMapping("/display")
	@ResponseBody
	public String display(@RequestParam String time, @RequestParam(required = false, defaultValue = "15") int count) {
		return "";
	}

	@RequestMapping("/track")
	@ResponseBody
	public String track(@RequestParam String time, @RequestParam(required = false, defaultValue = "15") int count) {
		return "";
	}
	@RequestMapping("/track_tmp")
	@ResponseBody
	public String track_tmp(@RequestParam String time, @RequestParam(required = false, defaultValue = "15") int count) {
		return "";
	}

//	/**
//	 * 修复小时数据
//	 * @param time ： yyyyMMdd-HH:mm:ss
//	 * @return
//	 */
//	public <T> String fixData(String time, int count, final BaseDao<T> dao) {
//
//		if (count < 0 || count % 3 != 0) {
//			return "count 必须是3的倍数！";
//		}
//
//		try {
//			Date date = DateUtils.parseDate(time, "yyyyMMdd-HH:mm:ss");
//			final long hour = DateUtils.truncateToHour(date.getTime());
//
//			String hourKey = StringUtils.joinWithUnderline(dao.getTableName(), "mdmap", "hour", hour);
//			dao.delRedisKey(hourKey);
//			System.out.println(hourKey);
//			Stopwatch watch = Stopwatch.createStarted();
//			int total = 3600000;
//			final int block = total / count;
//			final CountDownLatch cdl = new CountDownLatch(count);
//			for (int i = 0; i < total; i = i + block) {
//				final int num = i;
//				new Thread(new Runnable() {
//					@Override
//					public void run() {
//						for (int j = 0; j < block; j = j + 2000) {
//							long time = hour + num + j;
//							T param = dao.createModel(time);
//							dao.fixHourlyData(param);
//						}
//						cdl.countDown();
//					}
//				}).start();
//
//			}
//			cdl.await();
//			String result = String.format("fix %s data at %s, time %s", dao.getTableName(), DateUtils.dateFormat(hour), watch.stop().toString());
//			log.info(result);
//			return result;
//		} catch (ParseException e) {
//			return String.format("error time! format(%s)", "yyyyMMdd-HH:mm:ss");
//		} catch (Exception e) {
//			return ExceptionUtils.getStackTrace(e);
//		}
//
//	}
}
